A narrowing conversion is an implicit conversion to a destination type that cannot represent all values from the source type.
It can be a floating-point type converted to an integer type, or a type with a larger range of values converted to a type with a smaller range.
Narrowing conversions can lead to a loss of information and because they are implicit, they are not always obvious.
int a = 2.1f; // Noncompliant: loss of floating-point precision
long double f();
double d = 0;
d += f(); // Noncompliant: smaller range of values
Narrowing conversions should be fixed by either using a destination type that can represent all the source values or by using an explicit
conversion:
double a = 2.1f; // Compliant: double can represent all floats
long double f();
double d = 0;
d += static_cast<double>(f()); // Compliant: the intent is clear